#include "bob.h"

Bob::Bob(int id, int plid, QColor col, QWidget *parent) :
    QLabel(parent)
{
    this->id = id;
    this->plid = plid;
    this->col = col;




//    qDebug() << "cols" << col << col.lighter(150) << col.darker(150);

    nest = 0;
    state = unused;

    grad = new QRadialGradient();
    grad->setColorAt(0., col.lighter(150));
    grad->setColorAt(.35,col);
    grad->setColorAt(.80,col.darker(150));
    grad->setColorAt(.82,QColor(0,0,0,255));
    grad->setColorAt(.90,QColor(0,0,0,72));
    grad->setColorAt(1.,QColor(0,0,0,0));

    grad->setSpread(QGradient::PadSpread);



    resize(Nest::sz);
}

void Bob::resizeEvent(QResizeEvent *e) {
    if (!e->size().isEmpty()) {
        QPixmap pxm(e->size());
        pxm.fill(QColor(0,0,0,0));
        QPainter p(&pxm);
        int rad = qMin(pxm.width(),pxm.height())/2-1;

        grad->setCenter(pxm.rect().center());
        grad->setRadius(rad);

//        grad->setFocalPoint(pxm.width()*0.3,pxm.height()*0.4);
        grad->setFocalPoint(pxm.rect().center()-rad*QPointF(0.2,0.3));

        p.setBrush(QBrush(*grad));
        p.setPen(Qt::NoPen);
        p.drawEllipse(pxm.rect().center(),rad,rad);
        p.end();
        setPixmap(pxm);
//        qDebug() << "good bob size" << e->size() << rad << "grad"
//                 << grad->center() << grad->radius() << grad->focalPoint() ;
//    } else {
//        qDebug() << "bad bob size" << e->size();
    }

}

void Bob::mousePressEvent(QMouseEvent *ev) {
//    qDebug() << this << "picked";
    if (state != taken) emit got_me(this);
}



//void Bob::animmove()
